﻿using System;
using System.Linq;
using System.Windows.Forms;
using System.Windows.Input;



namespace Crm2011.Framework.Connect.Commands
{
    internal class DeleteProfileCommand : ICommand
    {
        private readonly ConnectionListView _view;



        public DeleteProfileCommand(ConnectionListView view)
        {
            _view = view;
        }



        public void Execute(object view)
        {
            string message = string.Format("Delete {0} profiles?", _view.SelectedItems.Count());
            var result = MessageBox.Show(message, "Profile delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
            if (result == DialogResult.Yes)
            {
                _view.DeleteSelectedItems();
            }
        }



        public bool CanExecute(object parameter)
        {
            return (_view.SelectedItems.Any());
        }



        public event EventHandler CanExecuteChanged;
    }
}